#include "GateHandler.h"
#include "JME_GLog.h"

void GateNetHandler::sessionConnectSucceed( JME_TcpSessionPtr session )
{
	static int _clientId = 1;

	session->start(_clientId++);

	LogT << "Client from [ " << session->getIp() << " ] connected" << LogEnd;
}

void GateNetHandler::sessionConnectFailed( JME_TcpSessionPtr session, boost::system::error_code e )
{

}

void GateNetHandler::sessionDisconnect( JME_TcpSessionPtr session, boost::system::error_code e )
{
	session->stop();

	LogT << "Client from [ " << session->getIp() << ":" << session->getNetId() << " ] disconnect" << LogEnd;
}

void GateNetHandler::sessionReceiveMessage( JME_TcpSessionPtr session, JME_Message::JME_MessagePtr msg )
{
	Dispatcher.execMessageHandler(msg->_msgId, session, msg);
}

void GateNetHandler::sessionReadError( JME_TcpSessionPtr session, boost::system::error_code e )
{
	session->stop();

	LogT << "Client from [ " << session->getIp() << ":" << session->getNetId() << " ] disconnect" << LogEnd;
}
